package com.ruoyi.iot.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.ruoyi.common.utils.DateUtils;

import com.ruoyi.iot.domain.IotDeviceData;
import com.ruoyi.iot.mapper.IotDeviceDataMapper;
import com.ruoyi.iot.service.IIotDeviceDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 设备数据Service业务层处理
 *
 * @author ruoyi
 * @date 2025-02-27
 */
@Service
public class IotDeviceDataServiceImpl implements IIotDeviceDataService {
    @Autowired
    private IotDeviceDataMapper iotDeviceDataMapper;

    /**
     * 查询设备数据
     *
     * @param dataId 设备数据主键
     * @return 设备数据
     */
    @Override
    public IotDeviceData selectIotDeviceDataByDataId(Long dataId) {
        return iotDeviceDataMapper.selectIotDeviceDataByDataId(dataId);
    }

    /**
     * 查询设备数据列表
     *
     * @param iotDeviceData 设备数据
     * @return 设备数据
     */
    @Override
    public List<IotDeviceData> selectIotDeviceDataList(IotDeviceData iotDeviceData) {
        return iotDeviceDataMapper.selectIotDeviceDataList(iotDeviceData);
    }

    /**
     * 新增设备数据
     *
     * @param iotDeviceData 设备数据
     * @return 结果
     */
    @Override
    public int insertIotDeviceData(IotDeviceData iotDeviceData) {
        iotDeviceData.setCreateTime(DateUtils.getNowDate());
        return iotDeviceDataMapper.insertIotDeviceData(iotDeviceData);
    }

    /**
     * 批量新增设备数据
     *
     * @param iotDeviceDataList 设备数据列表
     * @return 结果
     */
    @Override
    public int batchInsertIotDeviceData(List<IotDeviceData> iotDeviceDataList) {
        if (!CollUtil.isEmpty(iotDeviceDataList)) {
            return iotDeviceDataMapper.batchInsertIotDeviceData(iotDeviceDataList);
        } else {
            return 0;
        }

    }

    /**
     * 修改设备数据
     *
     * @param iotDeviceData 设备数据
     * @return 结果
     */
    @Override
    public int updateIotDeviceData(IotDeviceData iotDeviceData) {
        iotDeviceData.setUpdateTime(DateUtils.getNowDate());
        return iotDeviceDataMapper.updateIotDeviceData(iotDeviceData);
    }

    /**
     * 批量删除设备数据
     *
     * @param dataIds 需要删除的设备数据主键
     * @return 结果
     */
    @Override
    public int deleteIotDeviceDataByDataIds(Long[] dataIds) {
        return iotDeviceDataMapper.deleteIotDeviceDataByDataIds(dataIds);
    }

    /**
     * 删除设备数据信息
     *
     * @param dataId 设备数据主键
     * @return 结果
     */
    @Override
    public int deleteIotDeviceDataByDataId(Long dataId) {
        return iotDeviceDataMapper.deleteIotDeviceDataByDataId(dataId);
    }
}
